#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 4e5 + 5;

int n, n2;
ll a[N], sum[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  n2 = n * 2;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) a[i + n] = a[i];
  rep(i, 1, n2) sum[i] = sum[i - 1] + a[i];
  ll ans = a[1];
  deque<int> mn;
  mn.push_back(0);
  rep(i, 1, n2) {
    while (mn.size() && mn.front() + n < i) mn.pop_front();
    ans = max(ans, sum[i] - sum[mn.front()]);
    while (mn.size() && sum[mn.back()] >= sum[i]) mn.pop_back();
    mn.push_back(i);
  }
  cout << ans;
  return 0;
}